package com.hpin.fansea.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.bean.ServiceInfoVo;
import com.hpin.fansea.utils.Constant;

import java.util.List;

/**
 * Created by Aaron on 15/10/20.
 */
public class MyServiceAdapter extends BaseAdapter {

    private Context context;
    private List<ServiceInfoVo> serviceList;
    public MyServiceAdapter(Context context, List<ServiceInfoVo> serviceList) {
        this.context = context;
        this.serviceList = serviceList;
    }

    public void setServiceList(List<ServiceInfoVo> serviceList) {
        this.serviceList = serviceList;
    }

    @Override
    public int getCount() {
        return serviceList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_my_service, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tv_order = (TextView) convertView.findViewById(R.id.tv_order);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.tv_status = (TextView) convertView.findViewById(R.id.tv_status);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        switch (serviceList.get(position).serviceName) {

            case Constant.FW_XY:
                viewHolder.tv_type.setText("【洗衣】");
                break;
            case Constant.FW_JZ:
                viewHolder.tv_type.setText("【家政】");
                break;
            case Constant.FW_XC:
                viewHolder.tv_type.setText("【洗车】");
                break;
            case Constant.FW_KD:
                viewHolder.tv_type.setText("【快递】");
                break;
            case Constant.FW_FWZS:
                viewHolder.tv_type.setText("【租售】");
                break;
            case Constant.FW_PS:
                viewHolder.tv_type.setText("【配送】");
                break;
        }

//        //预约
//        viewHolder.tv_order.setText(serviceList.get(position).);
        //时间
        viewHolder.tv_time.setText(serviceList.get(position).subTime);
        //当前状态

        switch (serviceList.get(position).serviceStatus) {

            case Constant.SERVICE_STATUS_WAIT:

                viewHolder.tv_status.setText("待受理");

                break;
            case Constant.SERVICE_STATUS_ALREADY:

                viewHolder.tv_status.setText("已受理");

                break;
            case Constant.SERVICE_STATUS_FINSH:

                viewHolder.tv_status.setText("已完成");

                break;
            case Constant.SERVICE_STATUS_CANCEL:

                viewHolder.tv_status.setText("已取消");

                break;

        }

//        if (Constant.EXPRESS_RECEOVERED.equals(data.get(position).status))

//        else
//            viewHolder.tv_status.setText("当前状态: 未签收");

        return convertView;
    }

    private class ViewHolder {
        public TextView tv_type;
        public TextView tv_order;
        public TextView tv_time;
        public TextView tv_status;
    }
}